package com.tools.controller;

import animatefx.animation.FadeInUp;
import com.tools.constants.Constant;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.AnchorPane;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * IndexController
 *
 * @author < a href=" ">ZhangYang</ a>
 * @version v1.0.01
 * @date 2018-07-25 16:33
 */
public class IndexController extends BaseController {
  private static final Logger LOG = Logger.getLogger(IndexController.class);

  @FXML
  private Button menuBox;
  @FXML
  private MenuItem aboutMe;
  @FXML
  private MenuItem setting;

  @Override
  public void initialize(URL location, ResourceBundle resources) {

    System.out.println("master");

    /** 打开工具集窗口 **/
    menuBox.setOnAction(event -> {
      try {
        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(Thread.currentThread().getContextClassLoader().getResource(FXMLPage.MENU.getFxml()));
        AnchorPane menuOverview = loader.load();
        MenuController controller = loader.getController();
        controller.setPrimaryStage(this.getPrimaryStage());
        controller.setIndex(this.getIndex());
        this.getPrimaryStage().setTitle(Constant.STRING_TITLE_TOOLS);
        this.getIndex().setCenter(menuOverview);

        new FadeInUp(menuOverview).play();
      } catch (IOException e) {
        e.printStackTrace();
      }
    });

    /** 打开设置窗口 **/
    setting.setOnAction(event -> {
      try {
        SettingController controller = (SettingController) loadFXMLPage(
          Constant.STRING_TITLE_SETTING, FXMLPage.SETTING,false, false, false);

        controller.setPrimaryStage(this.getPrimaryStage());
        controller.showDialogStage();
      } catch (Exception e) {
        e.printStackTrace();
      }
    });

    /** 打开关于窗口 **/
    aboutMe.setOnAction(event -> {
      try {
        AboutMeController controller = (AboutMeController) loadFXMLPageUndecorated(
          Constant.STRING_TITLE_ABOUTME, FXMLPage.ABOUTMEPAGE, false);
        controller.setPrimaryStage(this.getPrimaryStage());
        controller.showDialogStage();
      } catch (Exception e) {
        e.printStackTrace();
      }
    });
  }
}
